package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.SsoUtil;
import org.jeecg.modules.system.entity.SysPosition;
import org.jeecg.modules.system.mapper.SysPositionMapper;
import org.jeecg.modules.system.service.ISysPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 岗位管理
 * @Author: jeecg-boot
 * @Date:   2019-07-31
 * @Version: V1.0
 */
@Service
public class SysPositionServiceImpl extends ServiceImpl<SysPositionMapper, SysPosition> implements ISysPositionService {

    @Autowired
    private SysPositionMapper sysPositionMapper;
    @Override
    public String selectByPositionId(List positionId) {
        return sysPositionMapper.selectByPositionId(positionId);
    }

    @Override
    public List<SysPosition> getAll() {
        return sysPositionMapper.getAll();
    }

    @Override
    public List<SysPosition> findPositionList(LoginUser user ) {
        List<SysPosition> list = new ArrayList<>();
        if (user.isAdmin()){  //超级管理员
           list =  sysPositionMapper.findPositionListByAdmin();
        } else {
            list =  sysPositionMapper.findPositionList(user.getTenantId());
        }
        return list;
    }

    @Override
    public void saveServerPosition(SysPosition sysPosition) {
        sysPosition.setId(String.valueOf(IdWorker.getId()));
        sysPosition.setCreateTime(new Date());
        sysPosition.setCreateBy(SsoUtil.getLoginUser().getId());
        sysPositionMapper.saveServerPosition(sysPosition);
    }

    @Override
    public IPage<SysPosition> findServerPage(Page<SysPosition> page, SysPosition sysPosition) {
        return sysPositionMapper.findServerPage(page,sysPosition);
    }


}
